//
//  KSInboundDiffDetailTableViewCell.swift
//  Supermarket
//
//  Created by liuxm on 2017/9/28.
//  Copyright © 2017年 kushao. All rights reserved.
//

import UIKit

/// 差异详情
class KSInboundDiffDetailTableViewCell: UITableViewCell {
    
    /// 产品图片
    lazy var productImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.frame = CGRect(x: 10, y: 0, width: 90, height: 90)
        
        self.addSubview(imageView)
        return imageView
    }()
    
    /// 说明
    lazy var productInfoLabel: UILabel = {
        let productInfoLabel = UILabel()
        productInfoLabel.font = UIFont.systemFont(ofSize: 15)
        productInfoLabel.textColor = KSColor.kColor_3
        productInfoLabel.numberOfLines = 0
        productInfoLabel.lineBreakMode = .byWordWrapping
        return productInfoLabel
    }()
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.selectionStyle = .none
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
    func initView(model: KSInboundDiffDetailDiffOrderGoodsModel) {
        /// 产品背景色
        let productView = UIView(frame: CGRect(x: 0, y: 0, width: KSConstants.kScreenWidth, height: 110))
        productView.backgroundColor = UIColor.colorWithHexString(hex: "#f9fafb")
        self.addSubview(productView)
        
        /// 产品图片
        productImageView.frame = CGRect(x: 10, y: 10, width: 90, height: 90)
        productImageView.sd_setImage(with: URL.init(string: model.goods_image), placeholderImage: UIImage.init(named: "Common_GoodsPlace"))
        productView.addSubview(productImageView)
        
        /// 产品简介
        productInfoLabel.frame = CGRect(x: productImageView.frame.size.width + productImageView.frame.origin.x
            + 10, y: productImageView.frame.origin.y, width: KSConstants.kScreenWidth - (productImageView.frame.size.width + productImageView.frame.origin.x) - 20, height: 40)
        productInfoLabel.text = model.goods_name
        productView.addSubview(productInfoLabel)
        
        let detailViewH:CGFloat = 90.0
        let bgView = UIView(frame: CGRect(x: 0, y: productView.frame.origin.y + productView.frame.size.height, width: KSConstants.kScreenWidth, height: detailViewH))
        self.addSubview(bgView)
        
        /// 进货数量
        let inNumLabel = UILabel(frame: CGRect(x: 10, y: 10, width: 150, height: 20))
        inNumLabel.font = UIFont.systemFont(ofSize: 15)
        inNumLabel.textColor = KSColor.kColor_3
        inNumLabel.text = "进货数量：\(model.goods_num)"
        bgView.addSubview(inNumLabel)
        
        /// 实到数量
        let autualNumLabel = UILabel(frame: CGRect(x: KSConstants.kScreenWidth - 160, y: inNumLabel.frame.origin.y, width: 150, height: 20))
        autualNumLabel.font = UIFont.systemFont(ofSize: 15)
        autualNumLabel.textColor = KSColor.kColor_3
        autualNumLabel.textAlignment = .right
        autualNumLabel.text = "实到数量：\(model.receive_num)"
        bgView.addSubview(autualNumLabel)
        
         /// 规格
        var specStr = ""
        for i in 0...(model.sku_details?.count)! - 1 {
            let skuDetailModel = model.sku_details![i]
            specStr = specStr + "\(skuDetailModel.name)：\(skuDetailModel.value)"
        }
       
        let specLabel = UILabel(frame: CGRect(x: 10, y: inNumLabel.frame.origin.y + inNumLabel.frame.size.height + 5, width: KSConstants.kScreenWidth - 20, height: 20))
        specLabel.font = UIFont.systemFont(ofSize: 15)
        specLabel.textColor = KSColor.kColor_3
        specLabel.text = specStr
        bgView.addSubview(specLabel)
        
        /// 备注
        let noteLabel = UILabel(frame: CGRect(x: 10, y: specLabel.frame.origin.y + specLabel.frame.size.height + 5, width: KSConstants.kScreenWidth - 20, height: 20))
        noteLabel.font = UIFont.systemFont(ofSize: 15)
        noteLabel.textColor = KSColor.kColor_9
        noteLabel.text = "备注：\(model.diff_mark.isEmpty ? "无" : model.diff_mark)"
        bgView.addSubview(noteLabel)
    }
}
